package com.dhl.fin.api.util;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.dhl.fin.api.domain.RemindTask;
import com.nlf.calendar.Lunar;

import java.util.Date;

/**
 * @author CuiJianbo
 * @since 2025/5/10
 */
public class SolarDateUtil {

    public static Date getSolarDate(RemindTask remindTask) {
        String[] indexs = remindTask.getLunarDayIndex().split(",");
        String[] remindTime = remindTask.getRemindTime().split(":");
        int year = DateUtil.year(DateUtil.date());
        Lunar midAutumn = new Lunar(year, Integer.parseInt(indexs[0]) + 1, Integer.parseInt(indexs[1]) + 1);
        DateTime dateTime = DateUtil.parseDateTime(String.format("%s %s:%s:00", midAutumn.getSolar().toString(), remindTime[0], remindTime[1]));

        if (dateTime.compareTo(DateUtil.date()) <= 0) {
            midAutumn = new Lunar(year + 1, Integer.parseInt(indexs[0]) + 1, Integer.parseInt(indexs[1]) + 1);
            dateTime = DateUtil.parseDateTime(String.format("%s %s:%s:00", midAutumn.getSolar().toString(), remindTime[0], remindTime[1]));
        }
        return dateTime;
    }

}
